from flask import Flask
from flask_sqlalchemy import SQLAlchemy

import socket
import psutil

useProxy = True



def getIp():
    ipv4s = []
    ipv6s = []
    dic = psutil.net_if_addrs() 
    for adapter in dic: 
        snicList = dic[adapter] 
        for snic in snicList: 
            if snic.family.name in {'AF_LINK', 'AF_PACKET'}: 
                mac = snic.address 
            elif snic.family.name == 'AF_INET': 
                addr = snic.address 
                if not addr.startswith('127.') and not addr.startswith('0.'):
                    if addr not in ipv4s:
                        ipv4s.append(addr)

            elif snic.family.name == 'AF_INET6': 
                addr = snic.address
                if not addr.startswith('fe80:') and not addr.startswith('fd7e:') and not addr.startswith(':'):
                    if addr not in ipv6s:
                        ipv6s.append(addr)
    return ipv4s, ipv6s

ipv4s, ipv6s = getIp()
#print(f'ipv4:{ipv4s}  ipv6:{ipv6s}')

isVPS = False
if '45.63.123.7' in ipv4s:
    isVPS = True

if isVPS:
    useProxy = False

proxyIp = "192.168.60.10"
#proxyIp = "[240e:381:b49:c900::1874]"

proxyHttpPort = 7890
proxySockPort = 7890
proxies = {"http": "http://%s:%d" % (proxyIp, proxyHttpPort), "https": "https://%s:%d" % (proxyIp, proxyHttpPort), }
#proxies = {"https":"socks5://%s:%d"% (proxyIp,proxySockPort)}

mysqlIp = "127.0.0.1"
mysqlPort = 3306

redisIp = "127.0.0.1"
redisPort = 6379
redisPassword = 'qwerty123456'

flaskapp = Flask(__name__)
flaskapp.config['SQLALCHEMY_DATABASE_URI'] = f'mysql+pymysql://root:qwerty123456@{mysqlIp}:{mysqlPort}/locallogdatabase'
# flaskapp.config['SQLALCHEMY_BINDS']  = {
#     'users': f'mysql+pymysql://root:qwerty123456@{mysqlIp}:{mysqlPort}/users', 

# }
flaskapp.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
flaskapp.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True

mysqldb = SQLAlchemy(flaskapp)


pushConfig = {
    'snso333':{'name':'snso333','code':'821529'},
    'westice':{'name':'westice','code':'452074'}
}
